class Storage {
  keys = new Set()

  set(key, value) {
    wx.setStorageSync(key, value);
    this.keys.add(key);
  }

  get(key) {
    return wx.getStorageSync(key);
  }

  use(key, value) {
    if (value) this.set(key, value);
    return [_ => this.get(key), (newValue) => this.set(key, newValue)]
  }

  remove(key) {
    wx.removeStorageSync(key);
    this.keys.delete(key);
  }

  clear() {
    wx.clearStorageSync();
    this.keys.clear();
  }

  has(key) {
    return this.keys.has(key);
  }
}

module.exports = new Storage();